﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace SimpleSocxs.manage
{
    public partial class page_stream : AuthorizedPage
    {
        protected string pageUrl;
        protected int pageID;
        protected void Page_Load(object sender, EventArgs e)
        {
            var pageBody = Request.Form["pageBody"];
                      
            pageID = int.Parse(Request["id"]);
            if (!string.IsNullOrEmpty(pageBody))
            {
                UpdatePage(pageBody);
            }
            
            pageUrl = Helper.GetPageUrlByID(pageID);
            ddlStreamID.DataSource = SocxsDataStore.Current.GetAllUserStreams(SocxsUser.ID);
            ddlStreamID.DataValueField = "ID";
            ddlStreamID.DataTextField = "Name";

            ddlRenderName.DataSource = Helper.GetFileNamesInUserAndShared(SocxsUser.Name, "renders/*.ascx").Select(_ => System.IO.Path.GetFileNameWithoutExtension(_));
            
            DataBind();
        }

        private void UpdatePage(string pageBody)
        {
            SocxsDataStore.Current.UpdatePageStreamPanels(pageID, pageBody);
        }
    }
}